//
//  CZMainTabBarController.swift
//  WHWeiBo
//
//  Created by Li Changjian on 16/7/9.
//  Copyright © 2016年 Li Changjian. All rights reserved.
//

import UIKit

class CZMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setUpChildControllers()
        
        //修改底部tabBar
        let czTabBar = CZTabBar()
        setValue(czTabBar, forKey: "tabBar")
        
        
        
        
    }
    
    
    // MARK: - 设置子控制器
    func setUpChildControllers() {
        
        addChildViewController(CZHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(CZMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(CZDiscoveryViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(CZProfileViewController(), title: "我的", imageName: "tabbar_profile")
    
    }
    // MARK: - 添加子控制器函数
    @objc private func addChildViewController(childController: UIViewController , title: String ,imageName: String) {
        
        childController.title = title
        childController.tabBarItem.title = title
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let navi = UINavigationController(rootViewController: childController)
        
        addChildViewController(navi)
        
    }

}
